package com.example.ShoppingManagementSystem.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.sql.Date;

@Setter
@Getter
@Entity
@Table(name = "product")
@EntityListeners(AuditingEntityListener.class)

public class Product {

    @Id
    @Column(name = "ProductID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "ProductName")
    private String name;

    @Column(name = "Manufacturer")
    private String manufacturer;

    @Column(name = "ProductionDate")
    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDateTime manufactureDate;

    @Column(name = "Model")
    private String model;

    @Column(name = "PurchasePrice")
    private Double purchasePrice;

    @Column(name = "RetailPrice")
    private Double retailPrice;

    @Column(name = "quantity")
    private Integer quantity;

    protected void onCreate() {
        if (manufactureDate == null) {
            manufactureDate = LocalDateTime.now();
        }
    }

    public Product(String name,String manufacturer, String model, Double purchasePrice, Double retailPrice, Integer quantity) {
        this.name = name;
        this.manufacturer = manufacturer;
        this.model = model;
        this.purchasePrice = purchasePrice;
        this.retailPrice = retailPrice;
        this.quantity = quantity;
    }

    public Product() {
    }

}
